Skip to content

Commit

Permalink
regression: disabled voip leaves empty section in the user menu (#33521)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva authored Oct 11, 2024
1 parent 02debbe commit 3bd14c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import React from 'react';
import UserMenuHeader from '../UserMenuHeader';
import { useAccountItems } from './useAccountItems';
import { useStatusItems } from './useStatusItems';
import { useVoipItems } from './useVoipItems';
import { useVoipItemsSection } from './useVoipItemsSection';

export const useUserMenu = (user: IUser) => {
const t = useTranslation();

const statusItems = useStatusItems();
const accountItems = useAccountItems();
const voipItems = useVoipItems();
const voipSection = useVoipItemsSection();

const logout = useLogout();
const handleLogout = useEffectEvent(() => {
Expand All @@ -37,15 +37,13 @@ export const useUserMenu = (user: IUser) => {
title: t('Status'),
items: statusItems,
},
{
items: voipItems,
},
voipSection,
{
title: t('Account'),
items: accountItems,
},
{
items: [logoutItem],
},
];
].filter((section) => section !== undefined);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useMutation } from '@tanstack/react-query';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';

const useVoipItems = (): GenericMenuItemProps[] => {
export const useVoipItemsSection = (): { items: GenericMenuItemProps[] } | undefined => {
const { t } = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();

Expand Down Expand Up @@ -45,23 +45,25 @@ const useVoipItems = (): GenericMenuItemProps[] => {

return useMemo(() => {
if (!isEnabled) {
return [];
return;
}

return [
{
id: 'toggle-voip',
icon: isRegistered ? 'phone-disabled' : 'phone',
disabled: !isReady || toggleVoip.isLoading,
onClick: () => toggleVoip.mutate(),
content: (
<Box is='span' title={tooltip}>
{isRegistered ? t('Disable_voice_calling') : t('Enable_voice_calling')}
</Box>
),
},
];
return {
items: [
{
id: 'toggle-voip',
icon: isRegistered ? 'phone-disabled' : 'phone',
disabled: !isReady || toggleVoip.isLoading,
onClick: () => toggleVoip.mutate(),
content: (
<Box is='span' title={tooltip}>
{isRegistered ? t('Disable_voice_calling') : t('Enable_voice_calling')}
</Box>
),
},
],
};
}, [isEnabled, isRegistered, isReady, tooltip, t, toggleVoip]);
};

export default useVoipItems;
export default useVoipItemsSection;
10 changes: 4 additions & 6 deletions apps/meteor/client/sidebar/header/hooks/useUserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import React from 'react';
import UserMenuHeader from '../UserMenuHeader';
import { useAccountItems } from './useAccountItems';
import { useStatusItems } from './useStatusItems';
import useVoipItems from './useVoipItems';
import { useVoipItemsSection } from './useVoipItemsSection';

export const useUserMenu = (user: IUser) => {
const t = useTranslation();

const statusItems = useStatusItems();
const accountItems = useAccountItems();
const voipItems = useVoipItems();
const voipItemsSection = useVoipItemsSection();

const logout = useLogout();
const handleLogout = useMutableCallback(() => {
Expand All @@ -37,15 +37,13 @@ export const useUserMenu = (user: IUser) => {
title: t('Status'),
items: statusItems,
},
{
items: voipItems,
},
voipItemsSection,
{
title: t('Account'),
items: accountItems,
},
{
items: [logoutItem],
},
];
].filter((section) => section !== undefined);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useMutation } from '@tanstack/react-query';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';

export const useVoipItems = (): GenericMenuItemProps[] => {
export const useVoipItemsSection = (): { items: GenericMenuItemProps[] } | undefined => {
const { t } = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();

Expand Down Expand Up @@ -45,23 +45,23 @@ export const useVoipItems = (): GenericMenuItemProps[] => {

return useMemo(() => {
if (!isEnabled) {
return [];
return;
}

return [
{
id: 'toggle-voip',
icon: isRegistered ? 'phone-disabled' : 'phone',
disabled: !isReady || toggleVoip.isLoading,
onClick: () => toggleVoip.mutate(),
content: (
<Box is='span' title={tooltip}>
{isRegistered ? t('Disable_voice_calling') : t('Enable_voice_calling')}
</Box>
),
},
];
return {
items: [
{
id: 'toggle-voip',
icon: isRegistered ? 'phone-disabled' : 'phone',
disabled: !isReady || toggleVoip.isLoading,
onClick: () => toggleVoip.mutate(),
content: (
<Box is='span' title={tooltip}>
{isRegistered ? t('Disable_voice_calling') : t('Enable_voice_calling')}
</Box>
),
},
],
};
}, [isEnabled, isRegistered, isReady, tooltip, t, toggleVoip]);
};

export default useVoipItems;

0 comments on commit 3bd14c1

Please sign in to comment.